//
//  DetailItemScrollView.m
//  PriceOnline
//
//  Created by Tai Le on 6/24/13.
//  Copyright (c) 2013 WorkLikeDance. All rights reserved.
//

#import "ControllersSwipeViewItem.h"
#import "UIConstants.h"
#import "BaseViewController.h"
#import "UIConstants.h"

@implementation ControllersSwipeViewItem

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        _contentView = [[UIView alloc]initWithFrame:RECT(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:_contentView];
        
        _lineViewLeft = [[UIView alloc]init];
        _lineViewLeft.backgroundColor = [UIColor blackColor];
        [self addSubview:_lineViewLeft];
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _lineViewLeft.frame = RECT(0, 0, 0, self.height);
    _contentView.frame = RECT(0, 0, self.width, self.height);
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
}

- (void)showViewController:(BaseViewController *)viewController
{
    [self removeViewController];
    
    if (viewController)
    {
        CGRect frame = RECT(0, 0, _contentView.width, _contentView.height);
        viewController.view.frame = frame;
        viewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [_contentView addSubview:viewController.view];
        _baseViewController = viewController;
        [viewController active];
    }
}

- (void)removeViewController
{
    if (_baseViewController)
    {
        [_baseViewController deactive];
        _baseViewController = nil;
    }
    
    [_contentView removeAllSubviews];
}
@end
